package csel.view;


import java.io.File;
import java.util.HashMap;
import csel.model.*;

public class RepresentationFactory {
	
	 private static RepresentationFactory instance;
     
     private final HashMap<GameObject,ObjectRepresentor> repSet;
     private final ObjectRepresentor defaultRep;
     private final GameObject defaultGObj;
     private final ObjectRepresentor emptyRep;
     
     public static RepresentationFactory getInstance()
     {
             if (instance == null)
                     instance = new RepresentationFactory();
             return instance;
     }
     
     private RepresentationFactory()
     {
             repSet = new HashMap<GameObject,ObjectRepresentor>();
             defaultGObj = new GameObject();
             defaultGObj.setTypeId("default");
             defaultRep = new ObjectRepresentor(defaultGObj);
             emptyRep = new ObjectRepresentor(null);
     }
     
     public ObjectRepresentor get(GameObject g)
     {
    	 	 if (g == null)
    	 	 {
    	 		 return emptyRep;
    	 	 }
             String gID = g.getTypeId();
             ObjectRepresentor o = repSet.get(g);
             if (o == null)
             {
                     File f = new File("images/"+gID+".png");
                     if (f.exists()) 
                             repSet.put(g, new ObjectRepresentor(g));
                     else 
                     {
                         System.out.println("No image found for "+gID);    
                    	 repSet.put(g, defaultRep);
                     }
                     o = repSet.get(g);
             }
             return o;       
     }

	
	
}
